﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;
using System.Diagnostics;

namespace MSDNWebcast.Converter
{
    public class RectangleToLargestSquareConverterX : IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Debug.Assert(values.Length == 2, "there should be two double values");
            Debug.Assert(values[0] is double, "value should be a double");
            Debug.Assert(values[1] is double, "value should be a double");
            Debug.Assert(targetType.IsAssignableFrom(typeof(double)), "value should be a double");
            var x = (double)values[0] / 704;
            var y = (double)values[1] / 528;
            return ((x > y) ? y : x)* 704;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class RectangleToLargestSquareConverterY : IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Debug.Assert(values.Length == 2, "there should be two double values");
            Debug.Assert(values[0] is double, "value should be a double");
            Debug.Assert(values[1] is double, "value should be a double");
            Debug.Assert(targetType.IsAssignableFrom(typeof(double)), "value should be a double");
            var x = (double)values[0] / 704;
            var y = (double)values[1] / 528;
            return ((x > y) ? y : x) * 528;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
